<?php
/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * @Date: 2022-04-21 15:27:10
 * @LastEditors: Sam
 * @LastEditTime: 2022-09-26 17:11:59
 */
namespace app\admin\model;
use think\Model;

class StoreCategory extends BaseModel {

        /**
     * 数据表主键
     * @var string
     */

    protected $pk = 'id';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;
    
     /**
     * 模型名称
     * @var string
     */
    protected $name = 'store_category';

       /**
     * 分级排序列表
     * @param null $model
     * @param int $type
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getTierList($model = null, $type = 0)
    {
        if ($model === null) $model = new self();
        if (!$type) return sort_list_tier($model->order('sort desc,id desc')->select()->toArray());
        return sort_list_tier($model->order('sort desc,id desc')->select()->toArray());
    }

    public function getPidCateAttr($value,$data){
        return self::where('id',$data['pid'])->value('cate_name') ?? '顶级分类';
    }
}